From 5203ad13954c28377fc4f0ffb7bfd2cf501303bb Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20H=C3=A4rdeman?= Date: Sun, 30 Nov 2025 23:13:39 +0100 Subject: [PATCH] statefiles: fix stale pio handling for !ubus MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Currently, config.c:odhcpd_reload() will call: set_config() // the piodir is set here set_interface() config_parse_interface() statefiles_read_prefix_information() statefiles_setup_dirfd() ubus_apply_network() config_parse_interface() statefiles_read_prefix_information() This works when ubus is enabled, because of the extra call to ubus_apply_network() which will read the pio file after the dirfd has been set up. However, it won't work when ubus isn't enabled since it'll turn ubus_apply_network() into a noop. Fix this by moving the statefiles_setup_dirfd() calls into set_config(), i.e. setup the dirfds as soon as the relevant cfg options have been read. Signed-off-by: David Härdeman Link: https://github.com/openwrt/odhcpd/pull/333 Signed-off-by: Álvaro Fernández Rojas --- src/config.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/config.c b/src/config.c index a79284c..cb971fd 100644 --- a/src/config.c +++ b/src/config.c @@ -492,6 +492,17 @@ static void set_config(struct uci_section *s) if ((c = tb[ODHCPD_ATTR_ENABLE_TZ])) config.enable_tz = blobmsg_get_bool(c); + if (config.dhcp_statefile) { + char *dir = dirname(strdupa(config.dhcp_statefile)); + char *file = basename(config.dhcp_statefile); + + memmove(config.dhcp_statefile, file, strlen(file) + 1); + statefiles_setup_dirfd(dir, &config.dhcp_statedir_fd); + } else { + statefiles_setup_dirfd(NULL, &config.dhcp_statedir_fd); + } + statefiles_setup_dirfd(config.dhcp_hostsdir, &config.dhcp_hostsdir_fd); + statefiles_setup_dirfd(config.ra_piodir, &config.ra_piodir_fd); } static void sanitize_tz_string(const char *src, uint8_t **dst, size_t *dst_len) @@ -2082,18 +2093,6 @@ void odhcpd_reload(void) } uci_unload(uci, system); - if (config.dhcp_statefile) { - char *dir = dirname(strdupa(config.dhcp_statefile)); - char *file = basename(config.dhcp_statefile); - - memmove(config.dhcp_statefile, file, strlen(file) + 1); - statefiles_setup_dirfd(dir, &config.dhcp_statedir_fd); - } else { - statefiles_setup_dirfd(NULL, &config.dhcp_statedir_fd); - } - statefiles_setup_dirfd(config.dhcp_hostsdir, &config.dhcp_hostsdir_fd); - statefiles_setup_dirfd(config.ra_piodir, &config.ra_piodir_fd); - vlist_flush(&lease_cfgs); ubus_apply_network(); -- 2.30.2